<script>
	import iconService from './services/icon.js';
	
	export default {
		onLaunch: function() {
			console.log('App Launch');
			// 加载TabBar图标
			this.loadTabBarIcons();
		},
		onShow: function() {
			console.log('App Show');
		},
		onHide: function() {
			console.log('App Hide');
		},
		methods: {
			// 加载TabBar图标
			loadTabBarIcons() {
				const iconCodes = [
					'tabbar_home',
					'tabbar_home_active', 
					'tabbar_navigation', 
					'tabbar_navigation_active',
					'tabbar_my',
					'tabbar_my_active'
				];
				
				iconService.getIconsMap(iconCodes)
					.then(iconsMap => {
						if (Object.keys(iconsMap).length > 0) {
							// 动态设置TabBar图标
							this.updateTabBarIcon(0, iconsMap['tabbar_home'] || '/static/tabbar/home.png', 
								iconsMap['tabbar_home_active'] || '/static/tabbar/home-active.png');
							
							this.updateTabBarIcon(1, iconsMap['tabbar_navigation'] || '/static/tabbar/home.png', 
								iconsMap['tabbar_navigation_active'] || '/static/tabbar/home-active.png');
							
							this.updateTabBarIcon(2, iconsMap['tabbar_my'] || '/static/tabbar/my.png', 
								iconsMap['tabbar_my_active'] || '/static/tabbar/my-active.png');
						}
					})
					.catch(err => {
						console.error('加载TabBar图标失败:', err);
					});
			},
			// 更新TabBar图标
			updateTabBarIcon(index, iconPath, selectedIconPath) {
				wx.setTabBarItem({
					index,
					iconPath,
					selectedIconPath,
					success: () => {
						console.log(`TabBar ${index} 图标更新成功`);
					},
					fail: (err) => {
						console.error(`TabBar ${index} 图标更新失败:`, err);
					}
				});
			}
		}
	}
</script>

<style>
	/*每个页面公共css */
</style>
